import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'package:leader_help/page/login/main/index.dart';
import 'package:leader_help/utils/component/component.dart';
import 'package:leader_help/utils/util.dart';

class LoginInputView extends GetView<LoginController> {
  const LoginInputView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final state = controller.state;
    return GetBuilder<LoginController>(
      builder: (_) => Container(
        child: Column(
          children: [
            TabBar(
                controller: state.tabCtrl,
                indicatorPadding: EdgeInsets.symmetric(horizontal: 30.r),
                labelColor: ColorsUtil.blue,
                unselectedLabelColor: ColorsUtil.title,
                labelStyle: TextStyle(fontSize: 16.sp),
                unselectedLabelStyle: TextStyle(fontSize: 16.sp),
                tabs: ['账号密码登录', '手机号登录']
                    .map(
                      (e) => Tab(
                        text: e,
                      ),
                    )
                    .toList()),
            SizedBox(
              height: 20.h,
            ),
            UITextField(
              controller: state.accountCtrl,
              hintText: '账户',
              prefixIcon: Icon(
                IconUtil.me,
                color: ColorsUtil.placeholder,
                size: 22.r,
              ),
              prefixWidth: 30.r,
              height: 44.r,
              border: Border.all(color: ColorsUtil.content, width: 0.5),
              backgroundColor: Colors.white,
            ),
            SizedBox(
              height: 20.h,
            ),
            Visibility(
              visible: state.tabCtrl.index == 0,
              child: UITextField(
                controller: state.pwdCtrl,
                hintText: '密码',
                prefixIcon: Icon(
                  IconUtil.pwd,
                  color: ColorsUtil.placeholder,
                  size: 22.r,
                ),
                prefixWidth: 30.r,
                height: 44.r,
                border: Border.all(color: ColorsUtil.content, width: 0.5),
                backgroundColor: Colors.white,
              ),
            ),
            Visibility(
              visible: state.tabCtrl.index == 1,
              child: CodeField(
                height: 44.r,
                isNeedBorder: true,
                controller: state.codeCtrl,
              ),
            ),
            SizedBox(
              height: 20.h,
            ),
            Container(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Obx(
                    () => TagItem(
                      text: '自动登录',
                      isActive: state.isAutoLogin.value,
                      onTap: () {
                        state.isAutoLogin.toggle();
                      },
                    ),
                  ),
                  InkWell(
                    onTap: controller.actionForget,
                    child: Text(
                      '忘记密码',
                      style: TextStyle(color: ColorsUtil.blue, fontSize: 15.sp),
                    ),
                  )
                ],
              ),
            ),
            SizedBox(
              height: 20.r,
            ),
            Row(
              children: [
                Expanded(
                  child: MaterialButton(
                    height: 44.r,
                    onPressed: controller.actionLogin,
                    color: ColorsUtil.blue,
                    child: Text(
                      '登录',
                      style:
                          pfMediumStyle(color: Colors.white, fontSize: 17.sp),
                    ),
                  ),
                )
              ],
            ),
            Container(
              alignment: Alignment.center,
              height: 80.r,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      Text(
                        '其他登录方式',
                        style: pfMediumStyle(
                            color: ColorsUtil.title, fontSize: 14.sp),
                      ),
                      SizedBox(
                        width: 10.r,
                      ),
                      InkWell(
                        onTap: controller.actionWxlogin,
                        child: loadImage(
                            url: 'icon_wechat.png'.imgPathLogin,
                            width: 30.r,
                            height: 30.r,
                            fit: BoxFit.contain),
                      ),
                      SizedBox(
                        width: 10.r,
                      ),
                      GetPlatform.isIOS
                          ? InkWell(
                              onTap: controller.actionApplelogin,
                              child: loadImage(
                                  url: 'icon_apple.png'.imgPathLogin,
                                  width: 30.r,
                                  height: 30.r),
                            )
                          : const SizedBox(),
                    ],
                  ),
                  InkWell(
                    onTap: controller.actionRegister,
                    child: Text(
                      '注册账户',
                      style: TextStyle(color: ColorsUtil.blue, fontSize: 15.sp),
                    ),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
